#ifndef __MSADO15_MGW_H__
#define __MSADO15_MGW_H__
/*//////////////////////
template<typename TI,typename TP>
class _ado_ptr_t
{
public:

    TP value;
    inline void Release()
    {value.Release();}
    inline const TI* intf()const
    {return value.GetInterfacePtr();}
    inline TI* & intf()
    {return value.GetInterfacePtr();}
    inline const TI* operator ->()const
    {return value.operator->();}
    inline TI* operator ->()
    {return value.operator->();}
    inline operator const TP& ()const
    {return value;}
    inline operator TP& ()
    {return value;}
    inline _ado_ptr_t(){}
    inline _ado_ptr_t(TI*pti):value(TP(pti)){}
    inline _ado_ptr_t(const TP&tp):value(tp){}
    inline _ado_ptr_t(const _ado_ptr_t & ptr):value(ptr.value){}
    inline _ado_ptr_t& operator =(const _ado_ptr_t&tp){value=tp.value;return *this;}
    inline _ado_ptr_t& operator =(const TP&tp){value=tp;return *this;}
    inline HRESULT CreateInstance(const CLSID &rclsid,IUnknown *pOuter = NULL,DWORD dwClsContext = CLSCTX_ALL) throw()
    {
        return value.CreateInstance(rclsid,pOuter,dwClsContext);
    }
    inline HRESULT CreateInstance(LPCWSTR clsidString,IUnknown *pOuter = NULL,DWORD dwClsContext = CLSCTX_ALL) throw()
    {
        return value.CreateInstance(clsidString,pOuter,dwClsContext);
    }
    inline HRESULT CreateInstance(LPCSTR clsidStringA,IUnknown *pOuter = NULL,DWORD dwClsContext = CLSCTX_ALL) throw()
    {
        return value.CreateInstance(clsidStringA,pOuter,dwClsContext);
    }
    inline TI *GetInterfacePtr() const throw() { return  value.GetInterfacePtr(); }
    inline TI*& GetInterfacePtr() throw() {return value.GetInterfacePtr();}

    inline void Attach(TI *pInterface) throw() {value.Attach(pInterface);}
    inline void Attach(TI *pInterface,bool fAddRef) throw() {value.Attach(pInterface,fAddRef);}
    inline TI *Detach() throw() {return value.Detach();}
    inline operator TI*() const throw() { return (TI*)value;}
    inline operator TI&() const {return (TI&)value; }
    inline TI& operator*() const {return *value;}
    inline TI **operator&() throw() {return &value;}
    inline operator bool() const throw() { return (bool)value; }
    inline bool operator==(int null) {return value.operator==(null);}
    inline bool operator==(long long null) {return value.operator==(null);}
    inline bool operator ==(const TP& tp){return value==tp;}
    inline bool operator ==(TI*pti){return value==pti;}
    inline bool operator ==(_ado_ptr_t & ptr){return value==ptr.value;}
    inline bool operator!=(int null) {return value.operator!=(null);}
    inline bool operator!=(long long null) {return value.operator!=(null);}
    inline bool operator !=(const TP& tp){return value!=tp;}
    inline bool operator !=(TI*pti){return value!=pti;}
    inline bool operator !=(_ado_ptr_t & ptr){return value!=ptr.value;}

    inline bool operator<(const TP& tp){return value<tp;}
    inline bool operator<(TI*pti){return value<pti;}
    inline bool operator<(_ado_ptr_t & ptr){return value<ptr.value;}

    inline bool operator>(const TP& tp){return value>tp;}
    inline bool operator>(TI*pti){return value>pti;}
    inline bool operator>(_ado_ptr_t & ptr){return value>ptr.value;}

    inline bool operator<=(const TP& tp){return value<=tp;}
    inline bool operator<=(TI*pti){return value<=pti;}
    inline bool operator<=(_ado_ptr_t & ptr){return value<=ptr.value;}

    inline bool operator>=(const TP& tp){return value>=tp;}
    inline bool operator>=(TI*pti){return value>=pti;}
    inline bool operator>=(_ado_ptr_t & ptr){return value>=ptr.value;}

};
///////////////////////////////////////////////*/
/*
QString var2str(_variant_t&var)
{
    if(var.vt==VT_NULL)
    {
        return QString("[NULL]");
    }
    if(var.vt==VT_DATE || var.vt==VT_FILETIME)
    {
        SYSTEMTIME st;
        VariantTimeToSystemTime(var,&st);
        return QString::asprintf("%04d-%02d-%02d %02d:%02d:%02d",
                                st.wYear,
                                st.wMonth,
                                st.wDay,
                                st.wHour,
                                st.wMinute,
                                st.wSecond);
    }else
    {
        return QString::fromUtf16((const char16_t *)(const wchar_t*)_bstr_t(var));
    }
}

template<typename ADO_FIELD,typename TSTREAM>
uint32_t ReadBlob(ADO_FIELD&pf,TSTREAM & buf)
{
    uint32_t sz=pf->GetActualSize();
    if(sz)
    {
        _variant_t var;
        do
        {
            uint32_t cz=std::max<uint32_t>(4096,sz);
            var=pf->GetChunk(cz);

            sz-=cz;
            char* pdata;
            SafeArrayAccessData(var.parray,(void**)&pdata);
            buf.write(pdata,cz);
            SafeArrayUnaccessData(var.parray);
        }while(sz);
    }
    return sz;
}
template<typename ADO_FIELD,typename TSTREAM>
uint32_t WriteBlob(ADO_FIELD&pf,TSTREAM & buf)
{
    uint32_t sz=0;
    uint32_t cz;
    _variant_t var;
    var.vt=VT_ARRAY | VT_UI1;
    SAFEARRAYBOUND sfb[1];
    sfb[0].cElements=4096;
    sfb[0].lLbound=0;
    var.parray=SafeArrayCreate(VT_UI1,1,sfb);
    char* pdata;
    do
    {
        SafeArrayAccessData(var.parray,(void**)&pdata);
        buf.read(pdata,4096);
        SafeArrayUnaccessData(var.parray);
        cz=buf.gcount();
        if(cz)
        {
            pf->AppendChunk(var);
            sz+=cz;
        }else
        {
            break;
        }
    }while(!buf.eof());
    return sz;
}


*/
namespace ADODB
{
#define __UUID_DESC(l1,s1,s2,c1,c2,c3,c4,c5,c6,c7,c8) {l1,s1,s2,{c1,c2,c3,c4,c5,c6,c7,c8}}
#define __DEFINE_UUID(name,id) const GUID name ## __uuidof = id
__DEFINE_UUID(_Collection,__UUID_DESC(0x00000512,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x6d,0x2e,0xa4));
__DEFINE_UUID(_DynaCollection,__UUID_DESC(0x00000513,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x6d,0x2e,0xa4));
__DEFINE_UUID(_ADO,__UUID_DESC(0x00000534,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x6d,0x2e,0xa4));
__DEFINE_UUID(Properties,__UUID_DESC(0x00000504,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x6d,0x2e,0xa4));
__DEFINE_UUID(Property,__UUID_DESC(0x00000503,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x6d,0x2e,0xa4));
__DEFINE_UUID(Error,__UUID_DESC(0x00000500,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x6d,0x2e,0xa4));
__DEFINE_UUID(Errors,__UUID_DESC(0x00000501,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x6d,0x2e,0xa4));
__DEFINE_UUID(Command15,__UUID_DESC(0x00000508,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x6d,0x2e,0xa4));
__DEFINE_UUID(_Connection,__UUID_DESC(0x00000550,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x6d,0x2e,0xa4));
__DEFINE_UUID(Connection15,__UUID_DESC(0x00000515,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x6d,0x2e,0xa4));
__DEFINE_UUID(_Recordset,__UUID_DESC(0x00000556,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x6d,0x2e,0xa4));
__DEFINE_UUID(Recordset21,__UUID_DESC(0x00000555,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x6d,0x2e,0xa4));
__DEFINE_UUID(Recordset20,__UUID_DESC(0x0000054f,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x6d,0x2e,0xa4));
__DEFINE_UUID(Recordset15,__UUID_DESC(0x0000050e,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x6d,0x2e,0xa4));
__DEFINE_UUID(Fields,__UUID_DESC(0x00000564,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x6d,0x2e,0xa4));
__DEFINE_UUID(Fields20,__UUID_DESC(0x0000054d,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x6d,0x2e,0xa4));
__DEFINE_UUID(Fields15,__UUID_DESC(0x00000506,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x6d,0x2e,0xa4));
__DEFINE_UUID(Field,__UUID_DESC(0x00000569,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x6d,0x2e,0xa4));
__DEFINE_UUID(Field20,__UUID_DESC(0x0000054c,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x6d,0x2e,0xa4));
__DEFINE_UUID(_Parameter,__UUID_DESC(0x0000050c,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x6d,0x2e,0xa4));
__DEFINE_UUID(Parameters,__UUID_DESC(0x0000050d,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x6d,0x2e,0xa4));
__DEFINE_UUID(Command25,__UUID_DESC(0x0000054e,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x6d,0x2e,0xa4));
__DEFINE_UUID(_Command,__UUID_DESC(0xb08400bd,0xf9d1,0x4d02,0xb8,0x56,0x71,0xd5,0xdb,0xa1,0x23,0xe9));
__DEFINE_UUID(ConnectionEventsVt,__UUID_DESC(0x00000402,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x6d,0x2e,0xa4));
__DEFINE_UUID(RecordsetEventsVt,__UUID_DESC(0x00000403,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x6d,0x2e,0xa4));
__DEFINE_UUID(ConnectionEvents,__UUID_DESC(0x00000400,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x6d,0x2e,0xa4));
__DEFINE_UUID(RecordsetEvents,__UUID_DESC(0x00000266,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x6d,0x2e,0xa4));
__DEFINE_UUID(ADOConnectionConstruction15,__UUID_DESC(0x00000516,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x6d,0x2e,0xa4));
__DEFINE_UUID(ADOConnectionConstruction,__UUID_DESC(0x00000551,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x6d,0x2e,0xa4));
__DEFINE_UUID(_Record,__UUID_DESC(0x00000562,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x6d,0x2e,0xa4));
__DEFINE_UUID(_Stream,__UUID_DESC(0x00000565,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x6d,0x2e,0xa4));
__DEFINE_UUID(ADORecordConstruction,__UUID_DESC(0x00000567,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x6d,0x2e,0xa4));
__DEFINE_UUID(ADOStreamConstruction,__UUID_DESC(0x00000568,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x6d,0x2e,0xa4));
__DEFINE_UUID(ADOCommandConstruction,__UUID_DESC(0x00000517,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x6d,0x2e,0xa4));
__DEFINE_UUID(ADORecordsetConstruction,__UUID_DESC(0x00000283,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x6d,0x2e,0xa4));
__DEFINE_UUID(Field15,__UUID_DESC(0x00000505,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x6d,0x2e,0xa4));
__DEFINE_UUID(Connection,__UUID_DESC(0x00000514,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x6d,0x2e,0xa4));
__DEFINE_UUID(Record,__UUID_DESC(0x00000560,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x6d,0x2e,0xa4));
__DEFINE_UUID(Stream,__UUID_DESC(0x00000566,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x6d,0x2e,0xa4));
__DEFINE_UUID(Command,__UUID_DESC(0x00000507,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x6d,0x2e,0xa4));
__DEFINE_UUID(Recordset,__UUID_DESC(0x00000535,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x6d,0x2e,0xa4));
__DEFINE_UUID(Parameter,__UUID_DESC(0x0000050b,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x6d,0x2e,0xa4));

#undef __UUID_DESC
#undef __DEFINE_UUID



struct  _Collection;
struct  _DynaCollection;
struct  _ADO;
struct  Properties;
struct  Property;
struct  Error;
struct  Errors;
struct  Command15;
struct  _Connection;
struct  Connection15;
struct  _Recordset;
struct  Recordset21;
struct  Recordset20;
struct  Recordset15;
struct  Fields;
struct  Fields20;
struct  Fields15;
struct  Field;
struct  Field20;
typedef long ADO_LONGPTR;
struct  _Parameter;
struct  Parameters;
struct  Command25;
struct  _Command;
struct  ConnectionEventsVt;
struct  RecordsetEventsVt;
struct  ConnectionEvents;
struct  RecordsetEvents;
struct  ADOConnectionConstruction15;
struct  ADOConnectionConstruction;
struct  Connection;
struct  _Record;
struct  Record;
struct  _Stream;
struct  Stream;
struct  ADORecordConstruction;
struct  ADOStreamConstruction;
struct  ADOCommandConstruction;
struct  Command;
struct  Recordset;
struct  ADORecordsetConstruction;
struct  Field15;
struct  Parameter;

//
// Smart pointer typedef declarations
//

#define __UUIDOF(name) name ## __uuidof
/////////////////*
_COM_SMARTPTR_TYPEDEF(IUnknown, IID_IUnknown);
_COM_SMARTPTR_TYPEDEF(IDispatch, IID_IDispatch);
_COM_SMARTPTR_TYPEDEF(_Collection, __UUIDOF(_Collection));
_COM_SMARTPTR_TYPEDEF(_DynaCollection, __UUIDOF(_DynaCollection));
_COM_SMARTPTR_TYPEDEF(_ADO, __UUIDOF(_ADO));
_COM_SMARTPTR_TYPEDEF(Properties, __UUIDOF(Properties));
_COM_SMARTPTR_TYPEDEF(Property, __UUIDOF(Property));
_COM_SMARTPTR_TYPEDEF(Error, __UUIDOF(Error));
_COM_SMARTPTR_TYPEDEF(Errors, __UUIDOF(Errors));
_COM_SMARTPTR_TYPEDEF(Command15, __UUIDOF(Command15));
_COM_SMARTPTR_TYPEDEF(Connection15, __UUIDOF(Connection15));
_COM_SMARTPTR_TYPEDEF(_Connection, __UUIDOF(_Connection));
_COM_SMARTPTR_TYPEDEF(Recordset15, __UUIDOF(Recordset15));
_COM_SMARTPTR_TYPEDEF(Recordset20, __UUIDOF(Recordset20));
_COM_SMARTPTR_TYPEDEF(Recordset21, __UUIDOF(Recordset21));
_COM_SMARTPTR_TYPEDEF(_Recordset, __UUIDOF(_Recordset));
_COM_SMARTPTR_TYPEDEF(Fields15, __UUIDOF(Fields15));
_COM_SMARTPTR_TYPEDEF(Fields20, __UUIDOF(Fields20));
_COM_SMARTPTR_TYPEDEF(Fields, __UUIDOF(Fields));
_COM_SMARTPTR_TYPEDEF(Field20, __UUIDOF(Field20));
_COM_SMARTPTR_TYPEDEF(Field, __UUIDOF(Field));
_COM_SMARTPTR_TYPEDEF(_Parameter, __UUIDOF(_Parameter));
_COM_SMARTPTR_TYPEDEF(Parameters, __UUIDOF(Parameters));
_COM_SMARTPTR_TYPEDEF(Command25, __UUIDOF(Command25));
_COM_SMARTPTR_TYPEDEF(_Command, __UUIDOF(_Command));
_COM_SMARTPTR_TYPEDEF(ConnectionEventsVt, __UUIDOF(ConnectionEventsVt));
_COM_SMARTPTR_TYPEDEF(RecordsetEventsVt, __UUIDOF(RecordsetEventsVt));
_COM_SMARTPTR_TYPEDEF(ConnectionEvents, __UUIDOF(ConnectionEvents));
_COM_SMARTPTR_TYPEDEF(RecordsetEvents, __UUIDOF(RecordsetEvents));
_COM_SMARTPTR_TYPEDEF(ADOConnectionConstruction15, __UUIDOF(ADOConnectionConstruction15));
_COM_SMARTPTR_TYPEDEF(ADOConnectionConstruction, __UUIDOF(ADOConnectionConstruction));
_COM_SMARTPTR_TYPEDEF(_Record, __UUIDOF(_Record));
_COM_SMARTPTR_TYPEDEF(_Stream, __UUIDOF(_Stream));
_COM_SMARTPTR_TYPEDEF(ADORecordConstruction, __UUIDOF(ADORecordConstruction));
_COM_SMARTPTR_TYPEDEF(ADOStreamConstruction, __UUIDOF(ADOStreamConstruction));
_COM_SMARTPTR_TYPEDEF(ADOCommandConstruction, __UUIDOF(ADOCommandConstruction));
_COM_SMARTPTR_TYPEDEF(ADORecordsetConstruction, __UUIDOF(ADORecordsetConstruction));
_COM_SMARTPTR_TYPEDEF(Field15, __UUIDOF(Field15));
///////////////////////////*/
/*///////////////////////////*
typedef _com_ptr_t<_com_IIID<IUnknown,&IID_IUnknown> > IUnknownPtr;
typedef _com_ptr_t<_com_IIID<IDispatch,&IID_IDispatch> > IDispatchPtr;
typedef _com_ptr_t<_com_IIID<_Collection,&__UUIDOF(_Collection)> > _CollectionPtr;
typedef _com_ptr_t<_com_IIID<_DynaCollection,&__UUIDOF(_DynaCollection)> > _DynaCollectionPtr;
typedef _com_ptr_t<_com_IIID<_ADO,&__UUIDOF(_ADO)> > _ADOPtr;
typedef _com_ptr_t<_com_IIID<Properties,&__UUIDOF(Properties)> > PropertiesPtr;
typedef _com_ptr_t<_com_IIID<Property,&__UUIDOF(Property)> > PropertyPtr;
typedef _com_ptr_t<_com_IIID<Error,&__UUIDOF(Error)> > ErrorPtr;
typedef _com_ptr_t<_com_IIID<Errors,&__UUIDOF(Errors)> > ErrorsPtr;
typedef _com_ptr_t<_com_IIID<Command15,&__UUIDOF(Command15)> > Command15Ptr;
typedef _com_ptr_t<_com_IIID<Connection15,&__UUIDOF(Connection15)> > Connection15Ptr;
typedef _com_ptr_t<_com_IIID<_Connection,&__UUIDOF(_Connection)> > _ConnectionPtr;
typedef _com_ptr_t<_com_IIID<Recordset15,&__UUIDOF(Recordset15)> > Recordset15Ptr;
typedef _com_ptr_t<_com_IIID<Recordset20,&__UUIDOF(Recordset20)> > Recordset20Ptr;
typedef _com_ptr_t<_com_IIID<Recordset21,&__UUIDOF(Recordset21)> > Recordset21Ptr;
typedef _com_ptr_t<_com_IIID<_Recordset,&__UUIDOF(_Recordset)> > _RecordsetPtr;
typedef _com_ptr_t<_com_IIID<Fields15,&__UUIDOF(Fields15)> > Fields15Ptr;
typedef _com_ptr_t<_com_IIID<Fields20,&__UUIDOF(Fields20)> > Fields20Ptr;
typedef _com_ptr_t<_com_IIID<Fields,&__UUIDOF(Fields)> > FieldsPtr;
typedef _com_ptr_t<_com_IIID<Field20,&__UUIDOF(Field20)> > Field20Ptr;
typedef _com_ptr_t<_com_IIID<Field,&__UUIDOF(Field)> > FieldPtr;
typedef _com_ptr_t<_com_IIID<_Parameter,&__UUIDOF(_Parameter)> > _ParameterPtr;
typedef _com_ptr_t<_com_IIID<Parameters,&__UUIDOF(Parameters)> > ParametersPtr;
typedef _com_ptr_t<_com_IIID<Command25,&__UUIDOF(Command25)> > Command25Ptr;
typedef _com_ptr_t<_com_IIID<_Command,&__UUIDOF(_Command)> > _CommandPtr;
typedef _com_ptr_t<_com_IIID<ConnectionEventsVt,&__UUIDOF(ConnectionEventsVt)> > ConnectionEventsVtPtr;
typedef _com_ptr_t<_com_IIID<RecordsetEventsVt,&__UUIDOF(RecordsetEventsVt)> > RecordsetEventsVtPtr;
typedef _com_ptr_t<_com_IIID<ConnectionEvents,&__UUIDOF(ConnectionEvents)> > ConnectionEventsPtr;
typedef _com_ptr_t<_com_IIID<RecordsetEvents,&__UUIDOF(RecordsetEvents)> > RecordsetEventsPtr;
typedef _com_ptr_t<_com_IIID<ADOConnectionConstruction15,&__UUIDOF(ADOConnectionConstruction15)> > ADOConnectionConstruction15Ptr;
typedef _com_ptr_t<_com_IIID<ADOConnectionConstruction,&__UUIDOF(ADOConnectionConstruction)> > ADOConnectionConstructionPtr;
typedef _com_ptr_t<_com_IIID<_Record,&__UUIDOF(_Record)> > _RecordPtr;
typedef _com_ptr_t<_com_IIID<_Stream,&__UUIDOF(_Stream)> > _StreamPtr;
typedef _com_ptr_t<_com_IIID<ADORecordConstruction,&__UUIDOF(ADORecordConstruction)> > ADORecordConstructionPtr;
typedef _com_ptr_t<_com_IIID<ADOStreamConstruction,&__UUIDOF(ADOStreamConstruction)> > ADOStreamConstructionPtr;
typedef _com_ptr_t<_com_IIID<ADOCommandConstruction,&__UUIDOF(ADOCommandConstruction)> > ADOCommandConstructionPtr;
typedef _com_ptr_t<_com_IIID<ADORecordsetConstruction,&__UUIDOF(ADORecordsetConstruction)> > ADORecordsetConstructionPtr;
typedef _com_ptr_t<_com_IIID<Field15,&__UUIDOF(Field15)> > Field15Ptr;
///////////////////////////////*/

}


#endif
